home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / COMM.SWG / 0041_Baud Rates.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-05  |  3KB  |  77 lines

  1. {
  2. Can anyone tell me how you would set the baud rate for a speed above 9600 BP
  3. in the bit mask for int 14h. also how you could do a Null modem type
  4. connection.
  5.  
  6. You can't.  You must program the divisor in the uart your self
  7. for those higher baudrates.  Here's part of a serial routine I
  8. use:
  9. }
  10.  
  11. Unit SerialIn;
  12. {F+}
  13. Interface
  14. Uses Crt,Dos;
  15. Const  CommPort   = $3F8;   { normally com1 = $3F8 and com2 = $2F8 }
  16.        CommIrq    = 4;      { normally com1 = 4 and com2 = 3 }
  17.        BaudRate   = 9600;   { 300 - 9600 }
  18.        Parameters = $03;    { 7 6 5  4 3  2  1 0
  19.                               +-+-+  +-+  |  +-+--- width 10 = 7 bits
  20.                               don't    |  |               11 = 8 bits
  21.                               care     |  +------- stopbit 0 = 1 bit
  22.                                        |                   1 = 2 bit
  23.                                        +---------- parity X0 = none
  24.                                                           01 = odd
  25.                                                           11 = even    }
  26.  
  27.        BufferSize = 1000; { Size of receiver buffer }
  28.        IntMask    : Array[2..5] of Byte = ($FB,$F7,$EF,$DF);
  29.  
  30. Var ComBuffer  : Array[0..Buffersize] of Byte;
  31.     HeadPtr,
  32.     TailPtr    : Integer;
  33.     OldCommInt : Pointer;
  34.  
  35. Procedure ComInit;                    { Initialize serial port }
  36. Procedure ComDisable;                 { Disable serial port }
  37. Procedure SendChar(Ch:Char);          { Send character to serial port }
  38. Procedure SendString(Message:String); { Send string to serial port}
  39. Function  GetChar:Char;               { Get character from serial port }
  40. Function  GetCharWait:Char;           { Wait for character ready, then get }
  41. Function  CharReady:Boolean;          { Returns true if character has been }
  42.                                       { received through serial port }
  43.  
  44. Implementation
  45.  
  46. Procedure ComInit;         { get the serial port ready for use }
  47. Var Divisor : Integer;     { this routine MUST be called before }
  48.     Dummy   : Integer;     { using serial port! }
  49.   Begin
  50.   Case BaudRate of
  51.      300 : Divisor := 384;
  52.     1200 : Divisor := 96;
  53.     2400 : Divisor := 48;
  54.     9600 : Divisor := 12;
  55.    19200 : Divisor := 6;
  56.     3840 : Divisor := 3;
  57.     5760 : Divisor := 2;
  58.    11520 : Divisor := 1;
  59.     Else WriteLn('Illegal Baudrate');
  60.     End;
  61.   Port[CommPort+3] := $80;                 { Set divisor latch bit }
  62.   Port[CommPort] := Lo(Divisor);           { Set lower divisor }
  63.  
  64.   Port[CommPort+1] := Hi(Divisor);         { set upper divisor }
  65.   Port[CommPort+3] := Parameters;          { clear divisor latch and }
  66.                                            { set data parameters }
  67.   HeadPtr := 0;                            { reset buffer pointers }
  68.   TailPtr := 0;
  69.   GetIntVec(CommIrq+8,OldCommInt);         { Save the old vector }
  70.   SetIntVec(CommIrq+8,@ComIntHandler);     { Install interrupt handler }
  71.   Port[CommPort+1] := 1;                   { Enable receiver interrupt }
  72.   Port[CommPort+4] := 9;                   { Enable DTR and OUT2 }
  73.   Port[$21] := Port[$21] And
  74.                          IntMask[CommIrq]; { Program 8259 Int mask }
  75.   Dummy := Port[CommPort];                 { Read the receiver register }
  76.   End;                                     { to clear status flags }
  77.